#ifndef _MUNIX_ABI_H_
#define	_MUNIX_ABI_H_
/*******************************************************************************
 ** Name: abi.h                                                               **
 ** Description:              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2010  Barry Gian James.                                **
 ** All rights reserved.                                                      **
 **                                                                           **
 ** Ref: $HeadURL$
 ******************************************************************************/
// Portions (C) 2011 OpenHouseware, LLC.

#define _MUNIX_ABI_H_ID "$Id$"
// Last Modified $DateTime$ by $Author$
#include "flashaddr.h"
#include "signals.h"

#define MAX_SYM_LEN     8
#define ABI_MAGIC_BIN	0xC0
#define ABI_MAGIC_LIB	0x0C

// What goes in our object file?
// 1. Header info, 2.object code, 3.relocation info, 4.symbols, 5.debugging data
// code: code; data: variables initialized with values (ie have space reserved)
// bss: variables uninitialized or initialized to zero(ie have no space reserved)
struct ABIHeader
{
	uint8_t   magic;
	FlashAddr  entry;      // entry point
	uint16_t  codeSz;
	uint16_t  dataSz;
	uint16_t  bssSz;
//    uint16  debugSz;    // debug symbol segment
	//uint16  symSz;      // symbol table size
	uint16_t  symNum;     // number of symbols in symtab
//    uint24  vBase;      // virtual mem base
//    uint24  sfBase;     // stack frame address (StackTop)
//    uint24  codeBase;   // base of code (CodeTop)
#ifdef SIGN_OBJECT_FILES
	uint64_t  sig;
	uint64_t  key;
#endif
};

struct ABISymTabEntry
{
	char    name[MAX_SYM_LEN+1];
	uint24_t  val;
	uint8_t   sz;         // size of the symbol (1byte, 2-bytes, address-size)
	bool    reloc;      // relocatable or absolute?
};

// Exceptions
enum class ABIException
{
	Unknown, DivideZero, IntOverflow, RangeCheck, NullPointer,
	Misaligned, InvalidASCII,

	ABIExceptions
};

// Signal Handler Interface
void handler(int signo, SigStack * stack, SigContext * context);

// Relocation Types


#endif	/* _MUNIX_ABI_H_ */

